package io.osw.modules.sys.controller;

import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;
import io.osw.common.validator.ValidatorUtils;
import io.osw.modules.sys.entity.TblCompanyEntity;
import io.osw.modules.sys.service.TblCompanyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 公司表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-07 10:54:28
 */
@RestController
@RequestMapping("sys/tblcompany")
public class TblCompanyController extends AbstractController{
    @Autowired
    private TblCompanyService tblCompanyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblcompany:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblCompanyService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping(value = "/name",method = RequestMethod.GET)
    public TblCompanyEntity list(@RequestParam String id){

        TblCompanyEntity tblCompanyEntity = tblCompanyService.selectById(id);
        return tblCompanyEntity;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{companyId}")
    @RequiresPermissions("sys:tblcompany:info")
    public R info(@PathVariable("companyId") Long companyId){
        TblCompanyEntity tblCompany = tblCompanyService.selectById(companyId);

        return R.ok().put("tblCompany", tblCompany);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblcompany:save")
    public R save(@RequestBody TblCompanyEntity tblCompany){
        tblCompany.setCreateTime(new Date());
        tblCompany.setCreateBy(getUserId());
        tblCompanyService.insert(tblCompany);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblcompany:update")
    public R update(@RequestBody TblCompanyEntity tblCompany){
        ValidatorUtils.validateEntity(tblCompany);
        tblCompany.setUpdateTime(new Date());
        tblCompany.setUpdateBy(getUserId());
        tblCompanyService.updateAllColumnById(tblCompany);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblcompany:delete")
    public R delete(@RequestBody Long[] companyIds){
        tblCompanyService.deleteBatchIds(Arrays.asList(companyIds));

        return R.ok();
    }

}
